////
//
/// \file ./include/inc/parser/indexed_name_node.hpp
//
//  Copyright 2007, 2008 Chandler Carruth
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
//  use this file except in compliance with the License.  You may obtain a copy
//  of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//  License for the specific language governing permissions and limitations
//  under the License.
//
////

#ifndef inc_parser_indexed_name_node_header
#define inc_parser_indexed_name_node_header

#include <string>
#include <vector>

#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>

#include <inc/parser/parse_tree_node.hpp>
#include <inc/parser/ws_parser.hpp>

namespace inc {
namespace parser {

class InternalNameNode;
class ExpressionNode;

/// \brief  Parse node for indexed names
/// \author Chandler Carruth
/// \date   2007.07.26
///
/// This represents a value with both a name and an index identifying it. This
/// is used for pointers and vectors, and can index in multiple dimensions.
/// Each index is required to be a pure expression for parsing.

class IndexedNameNode : public ParseTreeNode
{
public:
  typedef std::vector< boost::shared_ptr< ExpressionNode > > IndexChain;

  IndexedNameNode();
  virtual ~IndexedNameNode();

  virtual bool parse( const iterator& first,
                      const iterator& last,
                      iterator& last_parsed );

  /// \brief Accessor for the base internal name
  virtual InternalNameNode* get_base_name() const { return base_name.get(); }

  /// \brief Query the dimensions indexed
  virtual size_t index_dimensions() const { return indices.size(); }

  /// \brief Accessor for a particular index
  virtual ExpressionNode* index( int i ) const { return indices[i].get(); }

private:
  boost::scoped_ptr< InternalNameNode > base_name;
  IndexChain indices;

  boost::scoped_ptr< WSParser > ws;
};

} //  end parser namespace
} //  end inc namespace
#endif  //  inc_parser_indexed_name_node_header
